package com.ruoyi.service.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.service.api.RemoteServiceService;
import com.ruoyi.service.api.domain.CheService;
import com.ruoyi.service.api.domain.CheServiceItems;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.service.mapper.CheServiceItemsMapper;
import com.ruoyi.service.service.ICheServiceItemsService;

/**
 * 服务项目详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-03
 */
@Service
public class CheServiceItemsServiceImpl implements ICheServiceItemsService 
{
    @Autowired
    private CheServiceItemsMapper cheServiceItemsMapper;
    @Autowired
    private RemoteServiceService remoteServiceService;

    /**
     * 查询服务项目详情
     * 
     * @param id 服务项目详情主键
     * @return 服务项目详情
     */
    @Override
    public CheServiceItems selectCheServiceItemsById(Long id)
    {
        return cheServiceItemsMapper.selectCheServiceItemsById(id);
    }

    /**
     * 查询服务项目详情列表
     * 
     * @param cheServiceItems 服务项目详情
     * @return 服务项目详情
     */
    @Override
    public List<CheServiceItems> selectCheServiceItemsList(CheServiceItems cheServiceItems)
    {
        List<CheServiceItems> cheServiceItems1 = cheServiceItemsMapper.selectCheServiceItemsList(cheServiceItems);
        cheServiceItems1.forEach(e->{
            Long serviceId = e.getServiceId();
            AjaxResult info = remoteServiceService.getInfo(serviceId, null);
            Object o = info.get(AjaxResult.DATA_TAG);
            if (o==null){
                return;
            }
            CheService cheService = JSON.parseObject(JSON.toJSON(o).toString(), CheService.class);
            e.setCheService(cheService);
        });
        return cheServiceItems1;
    }

    /**
     * 新增服务项目详情
     * 
     * @param cheServiceItems 服务项目详情
     * @return 结果
     */
    @Override
    public int insertCheServiceItems(CheServiceItems cheServiceItems)
    {
        return cheServiceItemsMapper.insertCheServiceItems(cheServiceItems);
    }

    /**
     * 修改服务项目详情
     * 
     * @param cheServiceItems 服务项目详情
     * @return 结果
     */
    @Override
    public int updateCheServiceItems(CheServiceItems cheServiceItems)
    {
        return cheServiceItemsMapper.updateCheServiceItems(cheServiceItems);
    }

    /**
     * 批量删除服务项目详情
     * 
     * @param ids 需要删除的服务项目详情主键
     * @return 结果
     */
    @Override
    public int deleteCheServiceItemsByIds(Long[] ids)
    {
        return cheServiceItemsMapper.deleteCheServiceItemsByIds(ids);
    }

    /**
     * 删除服务项目详情信息
     * 
     * @param id 服务项目详情主键
     * @return 结果
     */
    @Override
    public int deleteCheServiceItemsById(Long id)
    {
        return cheServiceItemsMapper.deleteCheServiceItemsById(id);
    }
}
